﻿@model App
@{
    Layout = null;
}
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />

    <title>@Model.Name-App下載</title>
    <meta id="viewport" name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,minimal-ui">
</head>
<body>
    <div>
        <input id="androidUrl" type="hidden" value="@(Model.AndroidInfo?.Url)">
        <input id="iosUrl" type="hidden" value="@(Model.IosInfo?.Url)">
    </div>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script>
        (function ($) {
            var config = {
                /*scheme:必须*/
                scheme_IOS: '@Model.IosInfo.SchemalUrl',
                scheme_Adr: '@Model.AndroidInfo.SchemalUrl',
                android_url: document.getElementById('androidUrl').value,
                ios_url: document.getElementById('iosUrl').value,
                timeout: 600
            };

            function openclient() {
                var ifr = document.createElement('iframe');
                ifr.src = isIos() ? config.scheme_IOS : config.scheme_Adr;
                ifr.style.display = 'none';
                var startTime = Date.now();
                document.body.appendChild(ifr);

                var t = setTimeout(function () {
                    var endTime = Date.now();
                    if (!startTime || endTime - startTime < config.timeout + 10000) {
                        window.location = isIos() ? config.ios_url : config.android_url;
                    } else {

                    }
                }, config.timeout);

                window.onblur = function () {
                    clearTimeout(t);
                }
            }

            function isIos() {
                if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                    return true;
                }
                else if (navigator.userAgent.match(/android/i)) {
                    return false;
                }
            }

            $(function () {
                var startTime = Date.now();
                var t = setTimeout(function () {
                    var endTime = Date.now();
                    if (!startTime || endTime - startTime < 500) {
                        //這裡必須使用延時處理,直接調用不能打開app
                        openclient();
                    }
                });
                window.onblur = function () {
                    clearTimeout(t);
                }
            })
        })(jQuery)
    </script>
</body>
</html>